package com.prs.crm.action.official;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.official.DeptMailNum;
import com.prs.crm.domain.official.PersonalMailNum;
import com.prs.crm.service.official.DeptMailNumService;
import com.prs.crm.service.official.PersonalMailNumService;

public class PersonalMailNumAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private Integer[] ids;
	private PaginationSupport pagination;
	private PersonalMailNum personalMailNum;
	private PersonalMailNumService personalMailNumService;
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}

	public PersonalMailNum getPersonalMailNum() {
		return personalMailNum;
	}
	public void setPersonalMailNum(PersonalMailNum personalMailNum) {
		this.personalMailNum = personalMailNum;
	}
	public PersonalMailNumService getPersonalMailNumService() {
		return personalMailNumService;
	}
	public void setPersonalMailNumService(
			PersonalMailNumService personalMailNumService) {
		this.personalMailNumService = personalMailNumService;
	}
	@Action("listPersonalMailNum")
	public String listPersonalMailNum(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(PersonalMailNum.class);
		pagination=this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getPersonalMailNumService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	@Action("editPersonalMailNum")
	public String editPersonalMailNum(){
		if (ids!=null) {
			this.personalMailNum=this.getPersonalMailNumService().get(ids[0]);
		}
		return SUCCESS;
	}
	@Action(value = "savePersonalMailNum", results = {
			@Result(name = "success", type = "redirect", location = "listPersonalMailNum"),
			@Result(name = "error", type = "chain", location = "editPersonalMailNum") })
	public String savePersonalMailNum(){
		if (personalMailNum.getId()==null) {
			this.getPersonalMailNumService().save(personalMailNum);
		}else{
			this.getPersonalMailNumService().submit(personalMailNum);
		}
		return SUCCESS;
	}
	@Action(value = "removePersonalMailNum", results = {
			@Result(name = "success", type = "redirect", location = "listPersonalMailNum"),
			@Result(name = "error", type = "chain", location = "listPersonalMailNum") })
	public String removePersonalMailNum(){
		if (ids!=null) {
			this.personalMailNum=this.getPersonalMailNumService().get(ids[0]);
		}
		this.getPersonalMailNumService().batchRemove(ids);
		return SUCCESS;
	}
}
